<?php
if (isset($_POST['op'])){
    $data=$_POST['data'];
    $filePath='../upic/'.$_POST['op'];
    $data = str_replace('data:image/png;base64,', '', $data);
    $data = str_replace(' ', '+', $data);
    $imgdata = base64_decode($data);
    
    file_put_contents($filePath.'-2.png', $imgdata);
    
    
    $image = new Imagick('../img/template.jpg');
    $tu = new Imagick($filePath.'-2.png');
    $tu->resizeImage(610, 610,Imagick::FILTER_LANCZOS,1);
    
    $image->compositeImage($tu, Imagick::COMPOSITE_DEFAULT, 75, 290);
    
    $image->writeImage($filePath.'-u2.jpg');
    
    echo 200;
    
}
 